﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Data;
using System.Globalization;

namespace WpfClient.Classes
{
    [ValueConversion(typeof(DateTime), typeof(String))]

    public class DateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return null;
            else
                return (DateTime)value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DateTime resultDateTime;
             
            if (DateTime.TryParse(value.ToString(),System.Threading.Thread.CurrentThread.CurrentCulture,DateTimeStyles.AssumeLocal, out resultDateTime))
            {
                return resultDateTime;
            }

            return resultDateTime;
        }
    }
}
